#tag Class
Protected Class Slot
	#tag Method, Flags = &h21
		Private Sub Constructor()
		  //deprecated
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub Constructor(value as boolean)
		  active = value
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Sub Constructor(type as integer, sg as SlotGrid, tile as Tile, pos as string)
		  self.type = type
		  self.occupieable = true
		  self.sg = sg
		  self.tile = Tile
		  self.position = pos
		End Sub
	#tag EndMethod

	#tag Method, Flags = &h0
		Function GetType() As string
		  dim strType as String
		  
		  select case type
		  case 1
		    strType = "Grassland"
		  case 2
		    strType = "Street"
		  case 3
		    strType = "Town"
		  case 4
		    strType = "Monastery"
		  else
		    strType = "undefined"
		  end select
		  
		  return strType
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function PlaceGamepiece(gp as game . Gamepiece) As boolean
		  if active = true and occupieable = true and occupied = false then
		    occupier = gp
		    occupieable = false
		    occupied = true
		    select case type
		    case 1
		      occupier.setType game.Henchman.Peasant
		    case 2
		      occupier.setType game.Henchman.Highwayman
		    case 3
		      occupier.setType game.Henchman.Knight
		    case 4
		      occupier.setType game.Henchman.Monk
		    else
		      occupier.setType game.Henchman.Undefined
		    end select
		    occupier.bind (self)
		    occupier.add
		    
		    tile.SetOwner occupier.GetPlayer
		    
		    return true
		  else
		    return false
		  end if
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function RemoveGamepiece() As boolean
		  //remove the gamepiece from slot
		  if occupier <> nil and occupied = true then
		    occupier.remove
		    occupier = nil
		    occupied = false
		    occupieable = true
		    tile.RemoveOwner
		    return true
		  else
		    return false
		  end if
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function GetPosition() As string
		  //returns the original position of the slot (NorthIsOnTopState)
		  
		  return self.position
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function IsActive() As boolean
		  return active
		End Function
	#tag EndMethod


	#tag Note, Name = slotTypes
		
		1 = Grassland
		2 = Street
		3 = Town
		4 = Monastry
	#tag EndNote


	#tag Property, Flags = &h0
		active As boolean = true
	#tag EndProperty

	#tag Property, Flags = &h0
		type As Integer
	#tag EndProperty

	#tag Property, Flags = &h0
		occupieable As boolean = false
	#tag EndProperty

	#tag Property, Flags = &h0
		occupied As boolean = false
	#tag EndProperty

	#tag Property, Flags = &h0
		occupier As game.gamepiece
	#tag EndProperty

	#tag Property, Flags = &h0
		sg As SlotGrid
	#tag EndProperty

	#tag Property, Flags = &h0
		tile As Tile
	#tag EndProperty

	#tag Property, Flags = &h0
		#tag Note
			//this refers to the original position (NorthIsOnTopState)
		#tag EndNote
		position As string
	#tag EndProperty


	#tag ViewBehavior
		#tag ViewProperty
			Name="Name"
			Visible=true
			Group="ID"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Index"
			Visible=true
			Group="ID"
			InitialValue="-2147483648"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Super"
			Visible=true
			Group="ID"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Left"
			Visible=true
			Group="Position"
			InitialValue="0"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Top"
			Visible=true
			Group="Position"
			InitialValue="0"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="active"
			Group="Behavior"
			InitialValue="true"
			Type="boolean"
		#tag EndViewProperty
		#tag ViewProperty
			Name="type"
			Group="Behavior"
			InitialValue="0"
			Type="Integer"
		#tag EndViewProperty
		#tag ViewProperty
			Name="occupieable"
			Group="Behavior"
			InitialValue="false"
			Type="boolean"
		#tag EndViewProperty
		#tag ViewProperty
			Name="occupied"
			Group="Behavior"
			InitialValue="false"
			Type="boolean"
		#tag EndViewProperty
		#tag ViewProperty
			Name="position"
			Group="Behavior"
			Type="string"
			EditorType="MultiLineEditor"
		#tag EndViewProperty
	#tag EndViewBehavior
End Class
#tag EndClass
